package org.jeecg.modules.middleware.rabbitmq.gen.handler.impl;

import org.jeecg.modules.middleware.rabbitmq.gen.EnumGenHandler;
import org.jeecg.modules.middleware.rabbitmq.gen.handler.IGenMqHandle;
import org.jeecg.modules.paycenter.channel.tonglian.TongLianMemberService;
import org.jeecg.modules.wlhy.hycarrier.entity.HyCarrier;
import org.jeecg.modules.wlhy.hycarrier.service.IHyCarrierService;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriver;
import org.jeecg.modules.wlhy.hydriver.service.IHyDriverService;
import org.jeecg.modules.wlhy.tlaccount.entity.HyTlAccount;
import org.jeecg.modules.wlhy.tlaccount.service.IHyTlAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 上传通联照片异步任务
 */
@Service
public class TlUploadImgHandler implements IGenMqHandle {

    @Autowired
    private TongLianMemberService memberService;

    @Autowired
    private IHyTlAccountService tlAccountService;

    @Autowired
    private IHyDriverService driverService;

    @Autowired
    private IHyCarrierService carrierService;

    @Override
    public String getHandlerName() {
        return EnumGenHandler.TL_UPLOAD_IMG.getHandlerName();
    }

    @Override
    @Transactional
    public void handle(String channel , String msg) {
        if ("1".equals(channel)) {
            //上传司机 身份证正面、反面、 从业资格证
            String driverId = msg;
            HyDriver driver = driverService.getById(driverId);
            if (driver == null) {
                return;
            }
            HyTlAccount account = tlAccountService.getByUidForUpdate(driverId);
            if (account != null) {
                memberService.uploadDriverImg(driver, account);
                memberService.uploadDriverImg2(driver, account);
                memberService.uploadDriverTransportCertificateImg(account);
            }
        } else if ("2".equals(channel)) {
            //上传车队长 身份证正面、反面、 从业资格证
            String carrierId = msg;
            HyCarrier carrier = carrierService.getById(carrierId);
            if (carrier == null) {
                return;
            }
            HyTlAccount account = tlAccountService.getByUidForUpdate(carrierId);
            if (account != null) {
                memberService.uploadCarrierImg(account, carrier);
            }
        }
    }
}
